﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LinkCard.Model;
using LinkCard.Dao;
using LinkCard.Utils;

namespace LinkCard.ShopCP
{
    public partial class Admin : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["USER"] == null)
            {
                Response.Redirect("/login.aspx");
            }
            else
            {
                var sUserID = Session["USER"].ToString();
                if (Convert.ToBoolean(Session["SHOPADMIN"]) == false)
                {
                    this.lblUsername.Text = sUserID;
                }
                else
                {//trường hợp user là Admin Shop
                    try
                    {
                        int supplierID = Convert.ToInt32(sUserID);
                        var db = new TopLinkEntities();
                        var supplier = db.Supplier.Where(t => t.SupplierID == supplierID).FirstOrDefault();
                        this.lblUsername.Text = supplier.Name.ToString();
                    }
                    catch
                    {
                        this.lblUsername.Text = "Có lỗi!!!";
                    }
                }
            }
        }
    }
}